package com.example.demoweb.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

/**
 * @program: yooli
 * @description: 测试方法
 * @author: qiang.ye
 * @create: 2019-04-10
 **/
@RestController
public class HelloController {



    @RequestMapping("/hello")
    public String hello(String name){

        return "hello,welcom:"+name;
    }


    @RequestMapping("/getfile")
    public String getfile(HttpServletRequest request, HttpServletResponse response) throws IOException {

        URL url=new URL("http://localhost:8080/group2/M00/6E/C7/wKgIEFtyeBGAdqSkAAKPYI_nRA800.jpg");
        InputStream is=url.openStream();
        OutputStream os= response.getOutputStream();
        byte bf[]=new byte[1024];
        int length=0;
        while((length=is.read(bf, 0, 1024))!=-1){
            os.write(bf, 0, length);
        }
        is.close();
        os.close();

        return null;

    }



}
